package logic

import (
	"context"
	"house/houserpc/houserpc"

	"house/api/internal/svc"
	"house/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseAddLogic) HouseAdd(req *types.HouseAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.HouseRpc.HouseAdd(l.ctx, &houserpc.HouseAddRequest{
		UserId: req.UserId,
		Title:  req.Title,
		Price:  float32(req.Price),
		Rent:   float32(req.Rent),
		Area:   req.Area,
		City:   req.City,
		Way:    req.Way,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "添加房源成功",
		Data:    add,
	}, nil
	return
}
